﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DSkin;
using DSkin.DirectUI;
using DSkin.Forms;

namespace CADShowTools
{
    public partial class CurrentShowForm : DSkinForm
    {
        private readonly IntPtr _cadapphandle;
        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();
        public CurrentShowForm(IntPtr handle)
        {
            InitializeComponent();
            _cadapphandle = handle;
        }

        internal void Showinfo(string info, int showType)
        {
            HideAll();
            if (info == "") return;
            var pt = Cursor.Position;


            IntPtr foregetIntPtr = GetForegroundWindow();
            if (foregetIntPtr != this.Handle)
            {
                NativeMethods.SetForegroundWindow(this.Handle);
                NativeMethods.SetActiveWindow(_cadapphandle);
            }

    
            pt.Offset(10, 10);

            switch (showType)
            {
                case 1: //lable
                    dSkinLabel1.Text = info;
                    dSkinLabel1.Visible = true;
                    dSkinLabel1.Location = pt;
                    break;
                case 2: //HTML标签
                    dSkinHtmlLabel1.Text = info;
                    dSkinHtmlLabel1.Visible = true;
                    dSkinHtmlLabel1.Location = pt;

                    break;
                case 3: //列表
                    dSkinListBox1.Items.Clear();
                    var fv = info.Split('\n');
                    foreach (var s in fv)
                    {
                        dSkinListBox1.Items.Add(new DuiLabel
                        {
                            Text = s,
                            BackColor = dSkinListBox1.Items.Count%2 == 0 ? Color.AliceBlue : Color.Coral
                        });
                    }
                    dSkinListBox1.Visible = true;
                    dSkinListBox1.Location = pt;
                    break;
            }
        }

        private void HideAll()
        {
            foreach (Control control in Controls)
            {
                control.Visible = false;
            }
        }
    }
}